package com.ruoyi.llm.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.llm.dao.KnowledgeParagraphMapper;
import com.ruoyi.llm.domain.po.KnowledgeParagraphPo;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DataSource(DataSourceType.MASTER)
public class KnowledgeParagraphService extends ServiceImpl<KnowledgeParagraphMapper, KnowledgeParagraphPo> {


        public Integer getParagraphCount(String docId){
            LambdaQueryWrapper<KnowledgeParagraphPo> query=new LambdaQueryWrapper<>();
            query.eq(KnowledgeParagraphPo::getDocId,docId);
            return this.count(query);
        }

        public List<KnowledgeParagraphPo> getParagraphList(String docId){
            LambdaQueryWrapper<KnowledgeParagraphPo> query=new LambdaQueryWrapper<>();
            query.eq(KnowledgeParagraphPo::getDocId,docId);
            return this.list(query);
        }

        public String updateParagraph(KnowledgeParagraphPo updParaPo){
            if(updParaPo == null || StringUtils.isBlank(updParaPo.getParagraphId())){
                return "段落号不能为空";
            }

            if(updParaPo.getEnable() != 1 && updParaPo.getEnable() != 0){
                return "开启状态错误";
            }
            LambdaUpdateWrapper<KnowledgeParagraphPo> updateWrapper=new LambdaUpdateWrapper<>();
            updateWrapper.eq(KnowledgeParagraphPo::getParagraphId,updParaPo.getParagraphId());
            updateWrapper.set(KnowledgeParagraphPo::getEnable,updParaPo.getEnable());//设置列
            this.update(updateWrapper);
            return  "保存成功";
        }



}
